package com.flutter_webview_plugin;

import android.view.ViewGroup;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;

public class JavaScriptInterface {
    private WebView webView;

    public JavaScriptInterface(WebView webView) {
        this.webView = webView;
    }

    @JavascriptInterface
    public void finish() {
        if (webView.canGoBack()) {
            webView.goBack();
        } else {
            if (webView != null) {
                ViewGroup vg = (ViewGroup) (webView.getParent());
                vg.removeView(webView);
            }
            webView = null;
            FlutterWebviewPlugin.channel.invokeMethod("onDestroy", null);
        }
    }
}

